using System;
using System.Collections.Generic;
using System.Text;
using SharpMud.LPC;

namespace SharpMud.Net.Intermud3.Packets
{
    /// <summary>
    /// Represents the Intermud3's "who-req" packet, used to send a request for a mud's who-list
    /// </summary>
    public class WhoReq : GenericPacket
    {
        private const string _PacketType = "who-req";

        protected WhoReq()
            : base(new LPC.LpcArray((LpcString)_PacketType, (LpcInteger)5, (LpcString)"", (LpcString)"", (LpcString)"", (LpcString)""))
        {
        }

        protected WhoReq(LpcArray data)
            : base(data)
        {
            if (data.Count != 6)
                throw new InvalidPacketException("A 'who-req' packet requires 6 LpcObject's, to be created.");
        }

        public WhoReq(string originatorMud, string originatorUsername, string targetMud)
            : base(new LpcArray((LpcString)_PacketType, (LpcInteger)5, (LpcString)originatorMud, (LpcString)originatorUsername, (LpcString)targetMud, (LpcString)0))
        {
        }

        public override string PacketType
        {
            get
            {
                return _PacketType;
            }
            set
            {
                if (value == null)
                    throw new ArgumentNullException("value");
                if (value.Trim().ToLower() == _PacketType)
                    return;
                else
                    throw new InvalidOperationException("A specific packet-type instance cannot be assigned PacketType's.");
            }
        }

        public static GenericPacket CreatePacket(LpcArray data)
        {
            return new WhoReq(data);
        }

        static WhoReq()
        {
            GenericPacket.RegisterPacketType(_PacketType, WhoReq.CreatePacket);
        }
    }
}
